Deleting enumeration value

Hi Folks,

I have an enumerated datatype with several hundred values. To delete a large amount of the values from the type through the GUI is painfully slow, so I am putting a script together to identify the unwanted items based upon a string search, and delete them. I'm 50% there as I can identify the unwanted values and print them out to confirm.

Can anyone advise on how to do the actual deletion? I've spent two days trying to use the at modify perm to no avail.

Thanks in advance

Mark
 

int i 
AttrType at = find(current Module,"level2tran")
if(!null at && at.type == attrEnumeration)
{
    int offset = null 
        int length = null 
        bool matchCase = true 
        bool reverse = true
        for (i = 0; i < at.size; i++) 
        {
                string s = at.strings[i]
                string sub = "H."
                if (!findPlainText (s, sub, offset, length, matchCase, reverse))
                {
                        print (at.strings[i]) "\t"
                        //at = modify(at,"level2tran",new_strings,new_values,new_colors,new_descs,new_map,errMess)
                }             
        }
}

mwilliamson - Fri Oct 02 05:09:08 EDT 2009

Re: Deleting enumeration value
roybond - Fri Oct 02 09:06:02 EDT 2009

I think this may be what you are looking for....
 

bool removeEnumeration (AttrType at, string sRemVal) {
 
    bool bExists = false
    
    string sError = ""
    
    
    // Load Definition of provided Attribute Type
 
    if ( at != null ) {
    
        string atType = at.name 
        string an = sRemVal 
        string listNew[at.size-1 ] = null
        int values[at.size-1] = null
        int colors[at.size-1] = null
        int mapping[at.size-1] = null
        int i = 0 
    
    
    // Check if provided Enumeration exists in Attribute Type Definition
    
        for (i=0; i<at.size; i++) {
        
            string sEnumVal = at.strings[i]
            
            if ( sEnumVal == sRemVal ) {
 
                bExists = true
            }
        }
        
        
    // If Enumeration exists then Modify Attribute Type Definition
    
        if (bExists) {
        
            int j = 0
            
            for (i=0; i<at.size; i++) {
            
                string sEnumVal = at.strings[i]
                        
                if ( sEnumVal != sRemVal ) {
                
                    listNew[j] = sEnumVal
                    values[j] = 0
                    colors[j] = 0
                    mapping[j] = j
                    j++
                }
            }
            
            noError()
            
            modify(at, atType, listNew, values, colors, mapping, null)
            
            sError = lastError()
        
        }
    }
    
    // Return True is Modify was successful, else False
    
    return ((sError == "") && ( !bExists ))
}

 


regards,

Roy.

roy.bond@baesystems.com

 


Attachments

attachment_14301305_RemoveEnumeration.dxl

Re: Deleting enumeration value
llandale - Fri Oct 02 10:34:47 EDT 2009

roybond - Fri Oct 02 09:06:02 EDT 2009

I think this may be what you are looking for....
 

bool removeEnumeration (AttrType at, string sRemVal) {
 
    bool bExists = false
    
    string sError = ""
    
    
    // Load Definition of provided Attribute Type
 
    if ( at != null ) {
    
        string atType = at.name 
        string an = sRemVal 
        string listNew[at.size-1 ] = null
        int values[at.size-1] = null
        int colors[at.size-1] = null
        int mapping[at.size-1] = null
        int i = 0 
    
    
    // Check if provided Enumeration exists in Attribute Type Definition
    
        for (i=0; i<at.size; i++) {
        
            string sEnumVal = at.strings[i]
            
            if ( sEnumVal == sRemVal ) {
 
                bExists = true
            }
        }
        
        
    // If Enumeration exists then Modify Attribute Type Definition
    
        if (bExists) {
        
            int j = 0
            
            for (i=0; i<at.size; i++) {
            
                string sEnumVal = at.strings[i]
                        
                if ( sEnumVal != sRemVal ) {
                
                    listNew[j] = sEnumVal
                    values[j] = 0
                    colors[j] = 0
                    mapping[j] = j
                    j++
                }
            }
            
            noError()
            
            modify(at, atType, listNew, values, colors, mapping, null)
            
            sError = lastError()
        
        }
    }
    
    // Return True is Modify was successful, else False
    
    return ((sError == "") && ( !bExists ))
}

 


regards,

Roy.

roy.bond@baesystems.com

 

I think you mean...

mapping[j] = i  // '= i', not '= j'
 
     Also, using 'null' for an unused ErrMess gives me the hebegebes.  I'd do this:
string ErrMess = ""
modify(at, atType, listNew, values, colors, mapping, ErrMess)
     then ignore ErrMess

 


You could merge your two loops ... now that I think of it ... to make it more confusing. nm

I'd re-write this to accept some sort of skip list of either values to keep or values to remove and then issue one modify command. As it is, you will get a History record for each removed enumeration. For me, that would include functions like this:

 

 

Skip   skpRemoveEnums = createString()
 
void   RemoveEnumsPrepare()
{      delete(skpRemoveEnums)
       skpRemoveEnums = createString()
}
 
void   RemoveEnumsAddEnum(string Enum)
{      put(skpRemoveEnums, Enum, Enum)
}
 
void   RemoveEnumsProceed(AttrType at)
{      for i -> at.size
          if this actual enum is in the Skip
          then CountToBeRemoved++
          else remove that enum from Skip, and report it
 
       Declare vectors [at.size-CountToBeRemoved]
 
 
       for i -> at.size
          if this actual Enum is in the Skip 
          then do nothing
          else update your vectors, using mapping[j] = i
}
 
Calling scripts would Prepare, add list of Enums, then Proceed.

 

 

  • Louie

 

Re: Deleting enumeration value
llandale - Fri Oct 02 10:41:20 EDT 2009

Bond is suggesting that you call his function instead of your print statement. His function has a bug, do this: mapping[j] = i.

Nice to see I'm not the only one who lines up open braces vertical with the corresponding closing brace. For me its SOOOooooo much easier to read. And debug.

  • Louie

Re: Deleting enumeration value
mwilliamson - Fri Oct 02 11:55:27 EDT 2009

llandale - Fri Oct 02 10:41:20 EDT 2009
Bond is suggesting that you call his function instead of your print statement. His function has a bug, do this: mapping[j] = i.

Nice to see I'm not the only one who lines up open braces vertical with the corresponding closing brace. For me its SOOOooooo much easier to read. And debug.

  • Louie

Hi Roy and Louie.

Thanks for your valuable responses. I spotted the mapping [j] error and believe that I am almost there. The reason I am using the findPlainText perm is that there are a number of enum values which match the supplied string and I want to bin everything else.

I can't see any glaring issues with the below code but am now getting a DOORS access violation error on the modify line.
 

AttrType at = find(current Module,"level2tran")
if(!null at && at.type == attrEnumeration)
{
    string atType = at.name
        string listNew[at.size-1 ] = null
    int values[at.size-1] = null
    int colors[at.size-1] = null
    int mapping[at.size-1] = null
    int i = 0 
        
        int offset = null 
        int length = null 
        bool matchCase = true 
        bool reverse = true
        int j = 0
        for (i = 0; i < at.size; i++) 
        {
                string s = at.strings[i]
                string sub = "I."
                if (!findPlainText (s, sub, offset, length, matchCase, reverse))
                {
                   listNew[j] = s
                   values[j] = 0
                   colors[j] = 0
                   mapping[j] = i
                   j++
                }
                modify(at, atType, listNew, values, colors,mapping, null)
        }
}

 


Regards

Mark

ps You recommended the alignment of braces to me some time ago Louie and it seems to pay dividends when debugging

 

Re: Deleting enumeration value
mwilliamson - Fri Oct 02 11:57:22 EDT 2009

llandale - Fri Oct 02 10:41:20 EDT 2009
Bond is suggesting that you call his function instead of your print statement. His function has a bug, do this: mapping[j] = i.

Nice to see I'm not the only one who lines up open braces vertical with the corresponding closing brace. For me its SOOOooooo much easier to read. And debug.

  • Louie

Forgot to add that my Print statement was just a way for me to check the correct functioning of the findPlainText perm

Mark

Re: Deleting enumeration value
llandale - Mon Oct 05 18:39:27 EDT 2009

mwilliamson - Fri Oct 02 11:55:27 EDT 2009

Hi Roy and Louie.

Thanks for your valuable responses. I spotted the mapping [j] error and believe that I am almost there. The reason I am using the findPlainText perm is that there are a number of enum values which match the supplied string and I want to bin everything else.

I can't see any glaring issues with the below code but am now getting a DOORS access violation error on the modify line.
 

AttrType at = find(current Module,"level2tran")
if(!null at && at.type == attrEnumeration)
{
    string atType = at.name
        string listNew[at.size-1 ] = null
    int values[at.size-1] = null
    int colors[at.size-1] = null
    int mapping[at.size-1] = null
    int i = 0 
        
        int offset = null 
        int length = null 
        bool matchCase = true 
        bool reverse = true
        int j = 0
        for (i = 0; i < at.size; i++) 
        {
                string s = at.strings[i]
                string sub = "I."
                if (!findPlainText (s, sub, offset, length, matchCase, reverse))
                {
                   listNew[j] = s
                   values[j] = 0
                   colors[j] = 0
                   mapping[j] = i
                   j++
                }
                modify(at, atType, listNew, values, colors,mapping, null)
        }
}

 


Regards

Mark

ps You recommended the alignment of braces to me some time ago Louie and it seems to pay dividends when debugging

 

You are declaring your new vectors at the same size as the larger old vectors. You need an extra loop containing your findPlainText, but just counting positive ..err.. negative matches. Declare your various vectors that large and then populate them in the second loop.

I'd also go ahead and read the Values and Colors, and transfer them to the new vectors:
values[j] = at.values[i]
colors[j] = at.colors[i]

  • Louie

Re: Deleting enumeration value
mwilliamson - Tue Oct 06 05:05:14 EDT 2009

llandale - Mon Oct 05 18:39:27 EDT 2009
You are declaring your new vectors at the same size as the larger old vectors. You need an extra loop containing your findPlainText, but just counting positive ..err.. negative matches. Declare your various vectors that large and then populate them in the second loop.

I'd also go ahead and read the Values and Colors, and transfer them to the new vectors:
values[j] = at.values[i]
colors[j] = at.colors[i]

  • Louie

Many thanks Louie for your continued advice.

I've managed to get myself completely confused with the vector/pointers and unfotunately cannot waste any more time on this "helper script" I could have completed the task laboriously through the GUI in the time I have spent trying to get this "simple" script working.

I will come back to it later for my own sanity

Cheers

Mark